new Vue({
    el: ".container",
    data: {
        user: {},
        password2: "",
        tag: false
    },
    methods: {
        checkUsername: function () {
            if (this.user.username != "" && this.user.username != undefined) {
                axios({
                    url: `/user/checkUsername/${this.user.username}`
                }).then(res => {
                    if (!res.data.flag) {
                        layer.msg(res.data.message);
                        this.user.username = "";
                    }
                });
            }
        },
        checkEmail: function () {
            if (this.user.email != "" && this.user.email != undefined) {
                axios({
                    url: `/user/checkEmail/${this.user.email}`
                }).then(res => {
                    if (!res.data.flag) {
                        layer.msg(res.data.message);
                        this.user.email = "";
                    }
                });
            }
        },
        checkPassword: function () {
            if (this.user.password != undefined && this.user.password != "" && this.password2 != "") {
                if (this.user.password === this.password2) {
                    this.tag = true;
                } else {
                    layer.msg("两次密码不一致");
                    this.tag = false;
                }
            }
        },
        register: function () {
            if (this.tag) {
                if (this.user.username != "" && this.user.email != "" && this.password2 != "" && this.user.password != "") {
                    axios({
                        method: 'post',
                        url: '/user/register',
                        data: this.user
                    }).then(res => {
                        layer.msg(res.data.message);
                        if (res.data.flag) {
                            this.password2 = "";
                            this.user = {};
                        }
                    });
                } else {
                    layer.msg("信息有误");
                }
            } else {
                layer.msg("信息有误");
            }
        }
    }
})